home *** CD-ROM | disk | FTP | other *** search
Wrap
Option Explicit '================== 'Global Constants '================== Global Const KEY_RETURN = &HD Global Const CTRL_MASK = 2 Global Const MINIMIZED = 1 Global Const MSG = 0 Global Const TTL = 1 Global Const RETRY = 4 Global Const FIRST = 0 Global Const SECOND_ = 256 Global Const THIRD = 512 '====================== 'API/DLL Declarations '====================== Declare Function GetPrivateProfileString Lib "Kernel" (ByVal lpAppName As String, ByVal lpKeyName As String, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Integer, ByVal lpFileName As String) As Integer Declare Function WritePrivateProfileString Lib "Kernel" (ByVal lpAppName As String, ByVal lpKeyName As String, ByVal lpString As String, ByVal lplFileName As String) As Integer Declare Function GetWindowsDirectory Lib "Kernel" (ByVal lpBuffer As String, ByVal nSize As Integer) As Integer Declare Function GetSystemDirectory Lib "Kernel" (ByVal lpBuffer As String, ByVal nSize As Integer) As Integer ' Declare the fun needed to get the apps module handle Declare Function GetModuleHandle Lib "Kernel" (ByVal lpModuleName As String) As Integer ' Declares to make CTL3D.DLL work Declare Function Ctl3dRegister Lib "CTL3D.DLL" (ByVal hInstance As Integer) As Integer Declare Function Ctl3dAutoSubClass Lib "CTL3D.DLL" (ByVal hInstance As Integer) As Integer Declare Function Ctl3dUnregister Lib "CTL3D.DLL" (ByVal hInstance As Integer) As Integer '================== 'Global Variables '================== Global gintDefault As Integer Global gintIconstyle As Integer Global gintButtonStyle As Integer Global gintModal As Integer Global gstrCR As String Global gstrQ As String Global gstrTheMessage As String Global gstrRawMessage As String Global gstrTheTitle As String Sub CenterOnForm (Parent As Form, Child As Form) Dim pintChildTop As Integer Dim pintChildLeft As Integer pintChildTop = ((Parent.Height - Child.Height) / 2) + Parent.Top pintChildLeft = ((Parent.Width - Child.Width) / 2) + Parent.Left If pintChildTop + Child.Height > screen.Height - 10 Then pintChildTop = screen.Height - 10 - Child.Height ElseIf pintChildTop < 10 Then pintChildTop = 10 End If If pintChildLeft + Child.Width > screen.Width - 10 Then pintChildLeft = screen.Width - 10 - Child.Width ElseIf pintChildLeft < 10 Then pintChildLeft = 10 End If Child.Move pintChildLeft, pintChildTop End Sub ' Procedure Name: GetSysDir As String ' ' Arguments: None ' ' Note: Function will get the Windows System Directory ' Function GetSysDir () As String Dim pintSize As Integer Dim pintRetString As Integer Dim pstrRet As String * 255 'Create an empty string to be filled pintSize = 255 'uncertain - possibly length of fill string ' Call API to get the windows directory pintRetString = GetSystemDirectory(pstrRet, pintSize) ' Trim the return string GetSysDir = Left$(pstrRet, pintRetString) End Function ' Procedure Name: GetWinDir As String ' ' Arguments: None ' ' Note: Function will get the Windows Directory ' Function GetWinDir () As String Dim pintSize As Integer Dim pintRetString As Integer Dim pstrRet As String * 255 'Create an empty string to be filled pintSize = 255 'uncertain - possibly length of fill string ' Call API to get the windows directory pintRetString = GetWindowsDirectory(pstrRet, pintSize) ' Trim the return string GetWinDir = Left$(pstrRet, pintRetString) End Function ' Procedure: MakePath As String ' Arugments: szDir As String Full directory path (with optional ending "\") ' szFile As String Filename to append to directory ' Return: Resulting fully qualified path name. ' ' This function will add the two parts to return a fully qualified path name ' Function MakePath (szDir As String, szFile As String) As String If szDir = "" Then MakePath = szFile$ ElseIf szFile = "" Then MakePath = szDir$ ElseIf Mid$(szDir, Len(szDir), 1) = "\" Then MakePath = szDir + szFile Else MakePath = szDir + "\" + szFile End If End Function ' Procedure Name: ReadIni As String ' ' Arguments: AppName As String The String in the [] in the named ini file ' KeyName As String The string before the "=" in the ini file ' DefaultStr As String Will be returned if no string is found ' IniFileName As String File name and path to that file "c:\test\test.ini" ' ' Note: Function will read data from Private Profile (.ini) File ' Function ReadIni (AppName As String, KeyName As String, DefaultStr As String, IniFileName As String) As String Dim pintSize As Integer Dim pintRetString As Integer Dim pstrRet As String * 255 'Create an empty string to be filled pintSize = 255 'uncertain - possibly length of fill string ' Call API to read ini pintRetString = GetPrivateProfileString(AppName, KeyName, DefaultStr, pstrRet, pintSize, IniFileName) ' Trim the return string ReadIni = Left$(pstrRet, pintRetString) End Function ' Procedure Name: SaveIni ' ' Arguments: AppName As String The String in the [] in the named ini file ' IniFileName As String File name and path to that file "c:\test\test.ini" ' KeyName As String The string before the "=" in the ini file ' NewVal As String The string to be added to or changed in the ini file ' ' Note: Will update INI file ' Sub SaveIni (AppName As String, KeyName As String, NewVal As String, IniFileName As String) Dim pintResultCode As Integer pintResultCode = WritePrivateProfileString(AppName, KeyName, NewVal, IniFileName) If pintResultCode = 0 Then Call Turn3dOnOff MsgBox "Error updating INI file!", 16, "ERROR!" Call Turn3dOnOff End If End Sub ' Procedure: Turn3dOnOff ' Arguments: None ' ' Note: This sub will turn the 3d of the CTL3D.DLL or CTL3DV2.DLL on and off. ' This can be used throughout an app (saffer) or just once to trun it ' on then once to turn it off. ' Sub Turn3dOnOff () Static pintInst As Integer ' Holds the inst handle of the app Static pint3dOn As Integer ' Holds flag of if 3d is on (true) or off (false) Dim pintTemp As Integer ' Temp not to be used ' For safty exit function if no CTL3D.DLL in system dirs If Dir(MakePath(GetSysDir(), "CTL3D.DLL")) = "" And Dir(MakePath(GetWinDir(), "CTL3D.DLL")) = "" Then Exit Sub End If If pintInst = 0 Then ' If no inst handle retreved yet ' Get an inst handle for this app pintInst = GetModuleHandle((app.EXEName)) End If If pint3dOn Then ' If pint3dOn flag is true (3d is on) ' Unregister 3d (turn 3d off) pintTemp = Ctl3dUnregister(pintInst) pint3dOn = False Else ' Register 3d (turn 3d on) pintTemp = Ctl3dRegister(pintInst) pintTemp = Ctl3dAutoSubClass(pintInst) pint3dOn = True End If End Sub